﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using System.Xml.Serialization;
using Microsoft.Xna.Framework.Graphics;

namespace Urbania.GUI.Elements
{
    [Serializable]
    [XmlInclude(typeof(GUIElement))]
    public class TextElement : GUIElement
    {
        private string text;
        private string name;
        private Color textColor;
        private string fontPath;
        private SpriteFont font;

        public string Name { get { return this.name; } set { this.name = value; } }
        public string Text { get { return this.text; } set { this.text = value; } }
        public Color TextColor { get { return this.textColor; } set { this.textColor = value; } }
        public Vector2 Position { get { return this.position; } set { this.position = value; } }
        public string FontPath { get { return this.fontPath; } set { this.fontPath = value; } }
        public GUIElement Parent { get { return this.parent; } }
        public SpriteFont Font { get { return this.font; } }

        public TextElement()
        {
            this.name = "Default";
            this.text = "None";
            this.textColor = Color.White;
            this.font = Utilities.Loader.GetFont("Font\\default");
            this.fontPath = "Font\\default";
            this.position = Vector2.Zero;
            this.parent = null;
        }

        public TextElement(Vector2 position, string name, string text, Color color, GUIElement parent)
        {
            this.name = name;
            this.textColor = color;
            this.text = text;
            this.position = position;
            this.font = Utilities.Loader.GetFont("Font\\default");
            this.fontPath = "Font\\default";
            this.parent = parent;
        }

        public TextElement(Vector2 position, string name, string text, Color color, string font, GUIElement parent)
        {
            this.name = name;
            this.textColor = color;
            this.text = text;
            this.position = position;
            this.font = Utilities.Loader.GetFont(font);
            this.parent = parent;
            this.fontPath = font;
        }

        public override void Load()
        {
            this.font = Utilities.Loader.GetFont(this.fontPath);
        }

        public override void Update(GameTime gameTime) { }

        public override void Update(GameTime gameTime, Microsoft.Xna.Framework.Input.MouseState mouse) { }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(font, text, parent.GetPosition() + position, textColor);
        }
    }
}
